package com.x.uikit;


import android.os.Build;
import android.os.Handler;
import android.os.Looper;

import androidx.annotation.RequiresApi;

public class XThreadManager {
    private static Handler mMainHandler = new Handler(Looper.getMainLooper());

    public static void mainPost(Runnable runnable) {
        mMainHandler.post(runnable);
    }

    public static void runInMain(Runnable runnable) {
        if (isMainThread()) {
            runnable.run();
        } else {
            mainPost(runnable);
        }
    }

    public static boolean isMainThread() {
        return Looper.getMainLooper() == Looper.myLooper();
    }

    @RequiresApi(api = Build.VERSION_CODES.P)
    public static void mainPostDelayed(Runnable runnable, Object token, long delayMillis) {
        mMainHandler.postDelayed(runnable, token, delayMillis);
    }

    public static void mainPostDelayed(Runnable runnable, long delayMillis) {
        mMainHandler.postDelayed(runnable, delayMillis);
    }
}
